home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Shutdown FX 2.1 / source / sfx control app ƒ / sfx code ƒ / sfx meat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  8.5 KB  |  350 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        sfx meat.c
  4.  
  5. Purpose:    This module handles the fade modules folder: setting up
  6.             the two lists based on the initial information, setting
  7.             information of fades.
  8.  
  9. This program is free software; you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation; either version 2 of the License, or
  12. (at your option) any later version.
  13.  
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. GNU General Public License for more details.
  18.  
  19. You should have received a copy of the GNU General Public License
  20. along with this program in a file named "GNU General Public License".
  21. If not, write to the Free Software Foundation, 675 Mass Ave,
  22. Cambridge, MA 02139, USA.
  23.  
  24. \**********************************************************************/
  25.  
  26. #include "Folders.h"
  27. #include "sfx meat.h"
  28. #include "sfx install.h"
  29. #include "sfx gestalt.h"
  30. #include "sfx lists.h"
  31. #include "progress.h"
  32. #include "timing.h"
  33. #include "util.h"
  34. #include "file interface.h"
  35.  
  36. struct QDGlobals
  37. {
  38.     char privates[76];
  39.     long randSeed;
  40.     BitMap screenBits;
  41.     Cursor arrow;
  42.     Pattern dkGray;
  43.     Pattern ltGray;
  44.     Pattern gray;
  45.     Pattern black;
  46.     Pattern white;
  47.     GrafPtr thePort;
  48.     long    end;
  49. };
  50.  
  51. typedef struct QDGlobals QDGlobals;
  52. typedef pascal short (*FadeProcPtr)(Rect boundsRect, Pattern *thePattern);
  53.  
  54. long            gModuleDirID;
  55. short            gModuleVRefNum;
  56.  
  57. /* internal procedures for use in sfx meat.c only */
  58. static OSErr TouchFolder(FSSpec fs);
  59. static void DoTheDangFade(FadeProcPtr theFade);
  60.  
  61.  
  62. enum ErrorTypes SetUpLists(ListHandle usedList, ListHandle unusedList)
  63. {
  64.     CInfoPBRec        pb;
  65.     OSErr            isHuman;
  66.     Str255            theName;
  67.     long            systemDirID;
  68.     short            numModules;
  69.     short            i;
  70.     Boolean            noModules;
  71.     
  72.     isHuman=FindFolder(kOnSystemDisk, kSystemFolderType, kDontCreateFolder, &gModuleVRefNum,
  73.                 &systemDirID);                    /* find system folder */
  74.     if (isHuman!=noErr)
  75.         return kCantFindSystemFolder;
  76.     
  77.     pb.dirInfo.ioCompletion=0L;
  78.     pb.dirInfo.ioNamePtr=MODULE_FOLDER;
  79.     pb.dirInfo.ioVRefNum=gModuleVRefNum;
  80.     pb.dirInfo.ioFDirIndex=0;             /* very important */
  81.     pb.dirInfo.ioDrDirID=systemDirID;
  82.     isHuman=PBGetCatInfo(&pb, FALSE);    /* get info on "MSG Fades ƒ" folder */
  83.     if (isHuman!=noErr)
  84.         return kCantFindModuleFolder;
  85.     
  86.     gModuleDirID=pb.dirInfo.ioDrDirID;
  87.     numModules=pb.dirInfo.ioDrNmFls;
  88.     
  89.     MyClearAllCells(usedList);
  90.     MyClearAllCells(unusedList);
  91.     
  92.     noModules=TRUE;
  93.     
  94.     for (i=1; i<=numModules; i++)
  95.     {
  96.         pb.hFileInfo.ioCompletion=0L;
  97.         pb.hFileInfo.ioNamePtr=theName;
  98.         pb.hFileInfo.ioVRefNum=gModuleVRefNum;
  99.         pb.hFileInfo.ioFDirIndex=i;
  100.         pb.hFileInfo.ioDirID=gModuleDirID;
  101.         isHuman=PBGetCatInfo(&pb, FALSE);
  102.         if ((isHuman==noErr) && (!(pb.hFileInfo.ioFlAttrib&0x10)) &&
  103.             (pb.hFileInfo.ioFlFndrInfo.fdCreator==CREATOR))
  104.         {
  105.             /* got a fade module, now find out if it's used or unused and add to list */
  106.             
  107.             if (pb.hFileInfo.ioFlFndrInfo.fdType==USED_TYPE)
  108.             {
  109.                 MyAddStr255ToList(usedList, theName);
  110.                 noModules=FALSE;
  111.             }
  112.             else if (pb.hFileInfo.ioFlFndrInfo.fdType==UNUSED_TYPE)
  113.             {
  114.                 MyAddStr255ToList(unusedList, theName);
  115.                 noModules=FALSE;
  116.             }
  117.         }
  118.     }
  119.     
  120.     return noModules ? kNoModulesInFolder : allsWell;
  121. }
  122.  
  123. enum ErrorTypes DoTheDemoFade(ListHandle theList)
  124. {
  125.     Cell            theCell;
  126.     Str255            theName;
  127.     Handle            theProcHandle;
  128.     FadeProcPtr        theFade;
  129.     unsigned long    theSize;
  130.     FSSpec            fs;
  131.     short            oldRefNum, newRefNum;
  132.     Boolean            alreadyOpen;
  133.     OSErr            theResError;
  134.     Boolean            notDoneYet;
  135.     
  136.     if (!MyGetFirstSelectedCell(theList, &theCell))
  137.         return allsWell;
  138.     
  139.     notDoneYet=TRUE;
  140.     while ((LGetSelect(TRUE, &theCell, theList)) && (notDoneYet))
  141.     {
  142.         MyGetCellData(theList, theCell, theName);
  143.         LNextCell(FALSE, TRUE, &theCell, theList);
  144.         MyMakeFSSpec(gModuleVRefNum, gModuleDirID, theName, &fs);
  145.         theResError=OpenTheResFile(&fs, &oldRefNum, &newRefNum, &alreadyOpen);
  146.         if (theResError!=noErr)
  147.             return kCantOpenModule;
  148.         
  149.         theProcHandle=Get1Resource('PROC', 0);
  150.         if (((theResError=ResError())!=noErr) || (theProcHandle==0L))
  151.             return kModuleDamaged;
  152.         
  153.         if (*theProcHandle==0L)
  154.             LoadResource(theProcHandle);
  155.         if (*theProcHandle==0L)
  156.             return kModuleDamaged;
  157.         
  158.         theProcHandle=StripAddress(theProcHandle);
  159.         *theProcHandle=StripAddress(*theProcHandle);
  160.         
  161.         HLock(theProcHandle);
  162.         theFade=NewPtrSys(theSize=GetHandleSize(theProcHandle));
  163.         if (theFade==0L)
  164.         {
  165.             ReleaseResource(theProcHandle);
  166.             return kNoMemoryInSystemHeap;
  167.         }
  168.         
  169.         theFade=StripAddress(theFade);
  170.         
  171.         Mymemcpy(theFade, *theProcHandle, theSize);
  172.         ReleaseResource(theProcHandle);
  173.         theProcHandle=0L;
  174.         CloseTheResFile(oldRefNum, newRefNum, alreadyOpen);
  175.         DoTheDangFade(theFade);
  176.         DisposePtr(theFade);
  177.         theFade=0L;
  178.         notDoneYet=DealWithOtherPeople();
  179.     }
  180.     
  181.     return allsWell;
  182. }
  183.  
  184. void DoTheDangFade(FadeProcPtr theFade)
  185. {
  186.     short            oldMenuBarHeight;
  187.     long            oldA5;
  188.     QDGlobals        qd;                /* our QD globals. */
  189.     GrafPort        gp;                /* our grafport. */
  190.     GrafPtr            savePort;
  191.     short            whichWipe;
  192.     THz                saveZone;
  193.     unsigned long    temp;
  194.     
  195.     GetPort(&savePort);
  196.     oldMenuBarHeight=MBarHeight;
  197.     MBarHeight=0;
  198.     DrawMenuBar();
  199.  
  200.     /* get a value for A5, a structure that mirrors qd globals. */
  201.     oldA5 = SetA5((long)&qd.end);
  202.     InitGraf(&qd.thePort);
  203.     OpenPort(&gp);
  204.     
  205.     HideCursor();
  206.     
  207.     saveZone=GetZone();
  208.     SetZone(SysZone);
  209.  
  210.     theFade(gp.portRect, &qd.black);
  211.     
  212.     SetZone(saveZone);
  213.     
  214.     MBarHeight=oldMenuBarHeight;
  215.     ShowCursor();
  216.     ObscureCursor();
  217.     
  218.     ClosePort(&gp);
  219.     SetA5(oldA5);
  220.     SetPort(savePort);
  221.     
  222.     StartTiming();
  223.     TimeCorrection(10);
  224.     
  225.     DrawMenuBar();
  226.     PaintOne(0L, GetGrayRgn());
  227.     PaintBehind(WindowList, GetGrayRgn());
  228. }
  229.  
  230. enum ErrorTypes DoTheInstall(WindowDataHandle theData, ListHandle usedList,
  231.     ListHandle unusedList)
  232. {
  233.     Cell            theCell;
  234.     CInfoPBRec        pb;
  235.     OSErr            isHuman;
  236.     Str255            theName;
  237.     GrafPtr            curPort;
  238.     FSSpec            fs;
  239.     
  240.     if (!MyGetFirstSelectedCell(unusedList, &theCell))
  241.         return allsWell;
  242.     
  243.     while (LGetSelect(TRUE, &theCell, unusedList))
  244.     {
  245.         MyGetCellData(unusedList, theCell, theName);
  246.         LNextCell(FALSE, TRUE, &theCell, unusedList);
  247.         pb.hFileInfo.ioCompletion=0L;
  248.         pb.hFileInfo.ioNamePtr=theName;
  249.         pb.hFileInfo.ioVRefNum=gModuleVRefNum;
  250.         pb.hFileInfo.ioFDirIndex=0;
  251.         pb.hFileInfo.ioDirID=gModuleDirID;
  252.         isHuman=PBGetCatInfo(&pb, FALSE);
  253.         if (isHuman!=noErr)
  254.             return kCantGetModuleInfo;
  255.         
  256.         pb.hFileInfo.ioDirID=gModuleDirID;
  257.         pb.hFileInfo.ioFlFndrInfo.fdType=USED_TYPE;
  258.         isHuman=PBSetCatInfo(&pb, FALSE);
  259.         if (isHuman!=noErr)
  260.             return kCantSetModuleInfo;
  261.     }
  262.     
  263.     MyMakeFSSpec(gModuleVRefNum, gModuleDirID, theName, &fs);
  264.     TouchFolder(fs);
  265.     
  266.     LDoDraw(FALSE, usedList);
  267.     LDoDraw(FALSE, unusedList);
  268.     SetUpLists(usedList, unusedList);
  269.     LDoDraw(TRUE, usedList);
  270.     LDoDraw(TRUE, unusedList);
  271.     GetPort(&curPort);
  272.     SetPort((**unusedList).port);
  273.     EraseRect(&((**unusedList).rView));
  274.     SetPort(curPort);
  275.     
  276.     return allsWell;
  277. }
  278.  
  279. enum ErrorTypes DoTheRemove(WindowDataHandle theData, ListHandle usedList,
  280.     ListHandle unusedList)
  281. {
  282.     Cell            theCell;
  283.     CInfoPBRec        pb;
  284.     OSErr            isHuman;
  285.     Str255            theName;
  286.     GrafPtr            curPort;
  287.     FSSpec            fs;
  288.     
  289.     if (!MyGetFirstSelectedCell(usedList, &theCell))
  290.         return allsWell;
  291.     
  292.     while (LGetSelect(TRUE, &theCell, usedList))
  293.     {
  294.         MyGetCellData(usedList, theCell, theName);
  295.         LNextCell(FALSE, TRUE, &theCell, usedList);
  296.         pb.hFileInfo.ioCompletion=0L;
  297.         pb.hFileInfo.ioNamePtr=theName;
  298.         pb.hFileInfo.ioVRefNum=gModuleVRefNum;
  299.         pb.hFileInfo.ioFDirIndex=0;
  300.         pb.hFileInfo.ioDirID=gModuleDirID;
  301.         isHuman=PBGetCatInfo(&pb, FALSE);
  302.         if (isHuman!=noErr)
  303.             return kCantGetModuleInfo;
  304.         
  305.         pb.hFileInfo.ioDirID=gModuleDirID;
  306.         pb.hFileInfo.ioFlFndrInfo.fdType=UNUSED_TYPE;
  307.         isHuman=PBSetCatInfo(&pb, FALSE);
  308.         if (isHuman!=noErr)
  309.             return kCantSetModuleInfo;
  310.     }
  311.     
  312.     MyMakeFSSpec(gModuleVRefNum, gModuleDirID, theName, &fs);
  313.     TouchFolder(fs);
  314.     
  315.     LDoDraw(FALSE, usedList);
  316.     LDoDraw(FALSE, unusedList);
  317.     SetUpLists(usedList, unusedList);
  318.     LDoDraw(TRUE, usedList);
  319.     LDoDraw(TRUE, unusedList);
  320.     GetPort(&curPort);
  321.     SetPort((**usedList).port);
  322.     EraseRect(&((**usedList).rView));
  323.     SetPort(curPort);
  324.     
  325.     return allsWell;
  326. }
  327.  
  328. OSErr TouchFolder(FSSpec fs)
  329. {
  330.     CInfoPBRec        pb;
  331.     OSErr            isHuman;
  332.     
  333.     pb.dirInfo.ioCompletion=0L;
  334.     pb.dirInfo.ioVRefNum=fs.vRefNum;
  335.     pb.dirInfo.ioDrDirID=fs.parID;
  336.     pb.dirInfo.ioNamePtr=fs.name;
  337.     pb.dirInfo.ioFDirIndex=0;
  338.     if ((isHuman=PBGetCatInfo(&pb, FALSE))!=noErr)
  339.     {
  340.         FlushVol(0L, fs.vRefNum);
  341.         pb.dirInfo.ioDrDirID=pb.dirInfo.ioDrParID;
  342.         pb.dirInfo.ioFDirIndex=0;
  343.         GetDateTime(&(pb.dirInfo.ioDrMdDat));
  344.         isHuman=PBSetCatInfo(&pb, FALSE);
  345.         FlushVol(0L, fs.vRefNum);
  346.     }
  347.     
  348.     return isHuman;
  349. }
  350.